package com.larry.mr.reducejoin;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @ProjectName hadoop
 * @Author larry
 * @Date 15:37 2021/11/16
 * @Description TODO
 **/
public class ReduceJoinDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);

        //启动类
        job.setJarByClass(ReduceJoinDriver.class);

        //mapper    reducer
        job.setMapperClass(ReduceJoinMapper.class);
        //单一时 可不设置
        job.setReducerClass(ReduceJoinReducer.class);

        //map输出键值类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(OrderPd.class);

        //最终输出类型
        job.setOutputKeyClass(OrderPd.class);
        job.setOutputValueClass(NullWritable.class);

        //
        FileInputFormat.setInputPaths(job,new Path("C:\\Users\\larry\\IdeaProjects\\hadoop\\MapReduce\\src\\main\\resources\\reducejoin"));
        FileOutputFormat.setOutputPath(job,new Path("C:\\Users\\larry\\IdeaProjects\\hadoop\\MapReduce\\src\\main\\resources\\out1"));

        boolean flag = job.waitForCompletion(true);

        System.exit(flag ? 0 : 1);
    }
}
